var r = require;
r(['/assets/js/require.config.js'], function(config) {
  r.config(config);
  r(['refresh']);
  r([
    'hy5b/log/index',
    'hy5b/t/frontend',
    'hy5b/frontend/ua/index'
  ], function(log, t, ua) {

    function initCallBacks(win, options) {
      if (!win._initCallbacks) {
        win._initCallbacks = []
      }
      win._initCallbacks.push(options)
    }

    function createScript(win, options) {
      var head;
      var contendWin = win.contentWindow;
      initCallBacks(contendWin, options)
      var script = contendWin.document.createElement("script");
      script.type = "text/javascript";
      script.src = '/templet/cross-domain/js/anywhere.js';
      head = contendWin.document.getElementsByTagName("head")[0];
      if (!head) {
        head = document.createElement("head");
        contendWin.document.documentElement.appendChild(head)
      }
      head.appendChild(script);
      return script
    }

    var loginCallback = function() {

    }


    var anyWhereLoaded = function() {
      createScript(this, {
        requestType: 'login',
        callback: loginCallback
      })
    }

    function bind(scope, func) {
      return function() {
        return func.apply(scope, arguments)
      }
    }

    function createAnyWhereIframe() {
      var iframe;
      iframe = document.createElement("iframe");
      // iframe.style.display = "none";
      iframe.id = "anywhere_iframe";
      var callbackInIframe = bind(iframe, anyWhereLoaded);
      t.addEvent(iframe, "load", function() {
        callbackInIframe()
      });
      document.body.insertBefore(iframe, document.body.firstChild);
      try {
        var doc = iframe.contentWindow.document
      } catch (k) {
        console.log(k)
        if (ua.browser.ie) {
          iframe.src = "javascript:void((function(){document.open();document.domain='" + document.domain + "';document.close()})())"
        }
      }
      return iframe
    }
    window.iframeAnyWhere = createAnyWhereIframe();
  });

});
